# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=reportlab
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=3.4.0
pkgrel=1
pkgdesc="A proven industry-strength PDF generating solution (mingw-w64)"
arch=('any')
license=('custom')
url="https://www.reportlab.org/rl_toolkit.html"
depends=("${MINGW_PACKAGE_PREFIX}-freetype")
makedepends=("${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-python2-pip"
             "${MINGW_PACKAGE_PREFIX}-python3-pip"
             "${MINGW_PACKAGE_PREFIX}-python2-Pillow"
             "${MINGW_PACKAGE_PREFIX}-python3-Pillow")
_dtoken="87/f9/53b34c58d3735a6df7d5c542bf4de60d699cfa6035e113ca08b3ecdcca3f"
source=("https://pypi.python.org/packages/${_dtoken}/${_realname}-${pkgver}.tar.gz"
        "0001-Do-not-specialcase-quote-LIBART_VERSION-on-Windows.patch")
sha256sums=('5beaf35e59dfd5ebd814fdefd76908292e818c982bd7332b5d347dfd2f01c343'
            '084b3574f7cb83dc7c9412b9976d672fda0f5f20cef6c6f6b66a6cefc31220ef')

prepare() {
  pushd ${_realname}-${pkgver}
    patch -p1 < ${srcdir}/0001-Do-not-specialcase-quote-LIBART_VERSION-on-Windows.patch
  popd
  cp -r ${_realname}-${pkgver} build-python2
  cp -r ${_realname}-${pkgver} build-python3
}

build() {
  export FT_LIB=${MINGW_PREFIX}/lib/libfreetype.a
  export FT_INC=${MINGW_PREFIX}/include/freetype2
  # Build python 2 module
  cd "${srcdir}"/build-python2
  ${MINGW_PREFIX}/bin/python2 setup.py build

  # Build python 3 module
  cd "${srcdir}"/build-python3
  ${MINGW_PREFIX}/bin/python3 setup.py build
}

package_python2-reportlab() {
  depends+=("${MINGW_PACKAGE_PREFIX}-python2-pip"
            "${MINGW_PACKAGE_PREFIX}-python2-Pillow")

  cd "${srcdir}/build-python2"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX#\/} --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE.txt \
    "${pkgdir}${MINGW_PREFIX}"/share/licenses/python2-${_realname}/LICENSE
}

package_python3-reportlab() {
  depends+=("${MINGW_PACKAGE_PREFIX}-python3-pip"
            "${MINGW_PACKAGE_PREFIX}-python3-Pillow")

  cd "${srcdir}/build-python3"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX#\/} --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE.txt \
    "${pkgdir}${MINGW_PREFIX}"/share/licenses/python3-${_realname}/LICENSE
}

package_mingw-w64-i686-python2-reportlab() {
  package_python2-reportlab
}

package_mingw-w64-i686-python3-reportlab() {
  package_python3-reportlab
}

package_mingw-w64-x86_64-python2-reportlab() {
  package_python2-reportlab
}

package_mingw-w64-x86_64-python3-reportlab() {
  package_python3-reportlab
}
